package com.ssish.saas.eccs.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ssish.saas.eccs.common.BaseResult;
import com.ssish.saas.eccs.constant.db.vo.ocr.Configure;
import com.ssish.saas.eccs.constant.db.vo.ocr.OcrRequestVo;
import com.ssish.saas.eccs.constant.db.vo.ocr.OcrResponseDto;
import com.ssish.saas.eccs.service.OrcApiService;

@RefreshScope
@RestController
public class OrcApiController{
    @Autowired
    private OrcApiService orcApiService;
    
    @PostMapping("/api/ocrinterface")
    public BaseResult<OcrResponseDto> addProductForCore(@RequestBody OcrRequestVo ocrRequestVo) {
        System.out.println("begin");
        return orcApiService.getOcrResponseDtoFromOcr(ocrRequestVo);
    }
    @PostMapping("/visitor/api/ocrTest")
    public BaseResult<OcrResponseDto> ocrTest(MultipartFile file) {
        
        OcrRequestVo ocrRequestVo = new OcrRequestVo();
        try {
            String image = new String(Base64.encodeBase64(file.getBytes()));
            System.out.println(image);
           ocrRequestVo.setImage(image);
       } catch (IOException e) {
           // TODO Auto-generated catch block
            e.printStackTrace();
       }
        Configure configure = new Configure();
        List<String> template_list = new ArrayList<String>();
        template_list.add("a6720c74-823d-44a9-8036-9755ed9e6ad31577432536");
        template_list.add("76fad285-1014-4b1f-bad5-807bbd6d6fe61577438612");
        configure.setTemplate_list(template_list);
        ocrRequestVo.setConfigure(configure);
        return orcApiService.getOcrResponseDtoFromOcr(ocrRequestVo);
    }
}
